package cn.nubia.admin.sysconfig.bean;

import cn.nubia.admin.common.mybatis.annotations.Id;
import cn.nubia.admin.common.mybatis.annotations.Table;
import cn.nubia.admin.common.mybatis.annotations.UnColumn;
import org.hibernate.validator.constraints.NotBlank;

import java.io.Serializable;
import java.util.List;

/**
 * Created by justin on 15/7/29.
 * CREATE TABLE `t_sys_menus` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(32) NOT NULL COMMENT '菜单名称',
 `flag` varchar(64) NOT NULL COMMENT '标示',
 `link` varchar(512) NOT NULL COMMENT '连接',
 `open` tinyint(4) NOT NULL DEFAULT '0' COMMENT '1-为默认展开0－为默认关闭',
 `parentId` int(11) NOT NULL,
 `sortIndex` smallint(6) NOT NULL,
 `enable` tinyint(4) NOT NULL,
 `level` smallint(6) NOT NULL,
 PRIMARY KEY (`id`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 SET FOREIGN_KEY_CHECKS = 1;
 */
@Table(value = "t_sys_menus")
public class Menu implements Serializable,Comparable<Menu>{

    private static final long serialVersionUID = -8244661101951482489L;

    public static final String COLUMN_ISYS = "isys";

    public static final int ISYS_YES = 1;
    @Id
    private Integer id;
    @NotBlank(message = "菜单名不能为空")
    private String name;
    @NotBlank(message = "菜单标示不能为空")
    private String flag;

    private String link;

    private Integer parentId;

    private Integer sortIndex;

    private Integer enable;

    private Integer level;

    private String pcode;
    @UnColumn
    private String parentName;

    @UnColumn
    private List<Menu> subMenuList;

    private Integer isys;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getFlag() {
        return flag;
    }

    public void setFlag(String flag) {
        this.flag = flag;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public Integer getSortIndex() {
        return sortIndex;
    }

    public void setSortIndex(Integer sortIndex) {
        this.sortIndex = sortIndex;
    }

    public Integer getEnable() {
        return enable;
    }

    public void setEnable(Integer enable) {
        this.enable = enable;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public String getPcode() {
        return pcode;
    }

    public void setPcode(String pcode) {
        this.pcode = pcode;
    }

    public String getParentName() {
        return parentName;
    }

    public void setParentName(String parentName) {
        this.parentName = parentName;
    }

    public List<Menu> getSubMenuList() {
        return subMenuList;
    }

    public void setSubMenuList(List<Menu> subMenuList) {
        this.subMenuList = subMenuList;
    }

    public Integer getIsys() {
        return isys;
    }

    public void setIsys(Integer isys) {
        this.isys = isys;
    }

    @Override
    public int compareTo(Menu o) {
        if(this.getSortIndex()>o.getSortIndex())return 1;
        if(this.getSortIndex()<o.getSortIndex())return -1;
        return 0;
    }
}
